package com.example.demo.controller;


import com.example.demo.model.entity.CourseEntity;
import com.example.demo.model.param.CourseParam;
import com.example.demo.model.vo.ResponseVo;
import com.example.demo.service.CourseService;
import com.example.demo.untils.BuildResponseUtils;
import com.example.demo.untils.PageBean;
import com.example.demo.untils.PageVoUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CourseController  {

    @Autowired
    private CourseService courseService;


    @PostMapping("/addCourseInfo")
    public ResponseVo<?> addCourseInfo(@RequestBody CourseEntity courseEntity){
        return courseService.save(courseEntity) ? BuildResponseUtils.success():BuildResponseUtils.error();
    }


    @PostMapping("/updateCourseInfo")
    public ResponseVo<?> updateCourseInfo(@RequestBody CourseEntity courseEntity){
        return courseService.updateById(courseEntity) ? BuildResponseUtils.success():BuildResponseUtils.error();
    }


    @PostMapping("/listCourseInfo")
    public ResponseVo<?> listCourseInfo(@RequestBody CourseParam courseParam){
        PageInfo pageInfo = courseService.selectCourseList(courseParam);
        PageBean pageBean = PageVoUtils.convertTopageVo(pageInfo);
        return BuildResponseUtils.buildResponse(pageBean);
    }


    @PostMapping("/deleteCourseInfo")
    public ResponseVo<?> deleteCourseInfo(@RequestBody CourseEntity courseEntity){
        return courseService.removeById(courseEntity.getId()) ? BuildResponseUtils.success() : BuildResponseUtils.error();
    }


    @PostMapping("/uploadCourseVideo")
    public ResponseVo<?> uploadCourseVideo(){
        return null;
    }


    @PostMapping("/updateCourseVideo")
    public ResponseVo<?> updateCourseVideo(){
        return null;
    }

}
